package com.yuji.aacar.pay.paymanager;

import android.app.Activity;

import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.yuji.aacar.base.Const;
import com.yuji.aacar.tools.Tools;

import java.util.Map;


/**
 * Title: WxPayManager
 * Package:common.com.ttpc.consumer.commonsdk
 * Description: 微信支付
 * Copyright:ttpc All Rights Reserved
 * Author: shengshujie@126.com
 * version: V1.0
 * Date: 2017-01-10
 */
public class WxPayManager extends PayManager {
    private Activity mContext;
    private Map<String, String> mOrderInfo;
    private PayReq req;
    private IWXAPI api = null;

    public WxPayManager(Activity context) {
        super(context);
        mContext = context;
        api = WXAPIFactory.createWXAPI(context, null);
        req=new PayReq();
    }

    @Override
    protected void dopay(String result) {
        Map<String, String> Orderinfo = Tools.decodeXml(result);
        req.appId = Orderinfo.get("appid");
        req.partnerId = Orderinfo.get("partnerid");
        req.nonceStr = Orderinfo.get("noncestr");
        req.timeStamp = Orderinfo.get("timestamp");
        req.prepayId = Orderinfo.get("prepayid");
        req.packageValue = Orderinfo.get("package");
        req.sign = Orderinfo.get("sign");
        if (req.checkArgs()){
            sendPayReq(req);
        }

//        Toast.makeText(mContext,"weixin" + result ,Toast.LENGTH_SHORT).show();
    }

    /**
     *
     * 调起微信支付
     *
     */
    private void sendPayReq(PayReq req) {
        api.registerApp(Const.WX_APP_ID);
        api.sendReq(req);
    }
}
